﻿@model AntUnion.FrameWork.Model.Models.TbCity

@{
    ViewData["Title"] = "Create";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'upload'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , upload = layui.upload
                , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;

            /* 自定义验证规则 */
            form.verify({
                Cityid: function (value) {
                    if (value.length == 0) {
                        return '请输入城市代码';
                    }
                }
                , CiNameCn: function (value) {
                    if (value.length == 0) {
                        return '请输入城市名称';
                    }
                }
            });

            /* 监听提交 */
            form.on('submit(submit-form)', function (data) {
                $.ajax({
                    type: "POST",
                    url: "/Console/Cities/Create",
                    data: data.field, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            layer.msg("添加成功", { icon: 1, time: 1000 }, function () {
                                parent.layer.close(parentFrameIndex);
                                parent.layui.table.reload("table-datalist");
                            });
                        } else if (item.code == 1) {
                            layer.msg(item.data, { icon: 2 });
                        } else {
                            layer.msg("保存失败", { icon: 0 });
                        }
                        layer.closeAll('loading');
                    }
                });
                return false;
            });

        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">城市代码</label>
                    <div class="layui-input-block">
                        <input type="text" id="Cityid" name="Cityid" lay-verify="Cityid" placeholder="请输入城市代码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">城市名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="CiNameCn" name="CiNameCn" lay-verify="CiNameCn" placeholder="请输入城市名称" autocomplete="off" class="layui-input">
                        @if (ViewBag.type == 1)
                        {
                            <input id="CiprId" name="CiprId" value="@ViewBag.CountryId" type="hidden" />
                        }
                        else
                        {
                            <input id="CictId" name="CictId" value="@ViewBag.CountryId" type="hidden" />
                        }
                        <input id="State" name="State" value="@ViewBag.type" type="hidden" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">城市简称</label>
                    <div class="layui-input-block">
                        <input type="text" id="CiNameShort" name="CiNameShort" lay-verify="CiNameShort" placeholder="请输入城市简称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">英文名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="CiNameEn" name="CiNameEn" lay-verify="CiNameEn" placeholder="请输入英文名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">区号</label>
                    <div class="layui-input-block">
                        <input type="text" id="CiAreaCode" name="CiAreaCode" lay-verify="CiAreaCode" placeholder="请输入区号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮政编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="CiPostalCode" name="CiPostalCode" lay-verify="CiPostalCode" placeholder="请输入邮政编码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea name="CiRemark" id="CiRemark" placeholder="备注" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
